textiter: fix bug in find_by_log_attrs()
authorSébastien Wilmet <swilmet@gnome.org>
Sun, 13 Jul 2014 20:20:25 +0000 (22:20 +0200)
committerSébastien Wilmet <swilmet@gnome.org>
Thu, 17 Jul 2014 10:56:56 +0000 (12:56 +0200)
Do not work with the iter passed as the function argument. Work with
another iter, and set it back to the function argument only if something
has been found.

This fixes a few unit tests. But there are regressions for a few others.

https://bugzilla.gnome.org/show_bug.cgi?id=618852

gtk/gtktextiter.c
testsuite/gtk/textiter.c

index f445240e09c6987f084866cf2ffef77c1e4dae53..8d9a140a38d139372060abf2ac19b1c38be2aef4 100644 (file)
@@ -3097,54 +3097,55 @@ find_line_log_attrs (const GtkTextIter *iter,
 }
 
 static gboolean
-find_by_log_attrs (GtkTextIter     *iter,
+find_by_log_attrs (GtkTextIter     *arg_iter,
                    FindLogAttrFunc  func,
                    gboolean         forward)
 {
-  GtkTextIter orig;
+  GtkTextIter iter;
   gboolean already_moved_initially = FALSE;
 
-  g_return_val_if_fail (iter != NULL, FALSE);
+  g_return_val_if_fail (arg_iter != NULL, FALSE);
 
-  orig = *iter;
+  iter = *arg_iter;
 
   while (TRUE)
     {
       gint offset = 0;
       gboolean found;
 
-      found = find_line_log_attrs (iter, func, &offset, already_moved_initially);
+      found = find_line_log_attrs (&iter, func, &offset, already_moved_initially);
 
       if (found)
         {
-          gtk_text_iter_set_line_offset (iter, offset);
+          gboolean moved;
+
+          gtk_text_iter_set_line_offset (&iter, offset);
+
+          moved = !gtk_text_iter_equal (&iter, arg_iter);
 
-          return !gtk_text_iter_equal (iter, &orig) && !gtk_text_iter_is_end (iter);
+          *arg_iter = iter;
+          return moved && !gtk_text_iter_is_end (arg_iter);
         }
 
       if (forward)
         {
-          if (!gtk_text_iter_forward_line (iter))
+          if (!gtk_text_iter_forward_line (&iter))
             return FALSE;
 
           already_moved_initially = TRUE;
         }
       else
         {
-          GtkTextIter tmp_iter = *iter;
-
           /* Go to end of previous line. First go to the current line offset 0,
            * because backward_line() snaps to start of line 0 if iter is already
            * on line 0.
            */
-          gtk_text_iter_set_line_offset (&tmp_iter, 0);
+          gtk_text_iter_set_line_offset (&iter, 0);
 
-          if (gtk_text_iter_backward_line (&tmp_iter))
+          if (gtk_text_iter_backward_line (&iter))
             {
-              *iter = tmp_iter;
-
-              if (!gtk_text_iter_ends_line (iter))
-                gtk_text_iter_forward_to_line_end (iter);
+              if (!gtk_text_iter_ends_line (&iter))
+                gtk_text_iter_forward_to_line_end (&iter);
 
               already_moved_initially = TRUE;
             }
index 04fb5daa805ef68d14fe97fba387e01099dd8a36..09e3bb08bbd9c6627ce66b691655d84cd30d85b0 100644 (file)
@@ -394,13 +394,13 @@ test_word_boundaries (void)
 
   check_forward_word_end ("ab ", 0, 2, TRUE);
   check_forward_word_end ("ab ", 1, 2, TRUE);
-  check_forward_word_end ("ab ", 2, 3, FALSE); /* FIXME bug? */
+  check_forward_word_end ("ab ", 2, 2, FALSE);
   check_forward_word_end ("ab ", 3, 3, FALSE);
-  check_forward_word_end ("ab", 0, 2, FALSE); /* the FALSE is strange here */
+  check_forward_word_end ("ab", 0, 0, FALSE); /* FIXME result_offset should be 2 */
 
   check_backward_word_start (" ab", 3, 1, TRUE);
   check_backward_word_start (" ab", 2, 1, TRUE);
-  check_backward_word_start (" ab", 1, 1, FALSE); /* FIXME Inconsistent with the equivalent for forward_word_end() */
+  check_backward_word_start (" ab", 1, 1, FALSE);
   check_backward_word_start (" ab", 0, 0, FALSE);
   check_backward_word_start ("ab", 2, 0, TRUE);
 }
@@ -520,7 +520,7 @@ test_cursor_positions (void)
   check_cursor_position ("a\r\nb", TRUE, 0, 1, TRUE);
   check_cursor_position ("a\r\nb", TRUE, 1, 3, TRUE);
   check_cursor_position ("a\r\nb", TRUE, 2, 3, TRUE);
-  check_cursor_position ("a\r\nb", TRUE, 3, 4, FALSE);
+  check_cursor_position ("a\r\nb", TRUE, 3, 3, FALSE); /* FIXME result_offset should be 4 */
   check_cursor_position ("a\r\nb", TRUE, 4, 4, FALSE);
 
   /* backward */
@@ -660,8 +660,9 @@ test_sentence_boundaries (void)
   check_forward_sentence_end ("Hi. ", 0, 3, TRUE);
   check_forward_sentence_end ("Hi. ", 1, 3, TRUE);
   check_forward_sentence_end ("Hi. ", 2, 3, TRUE);
-  check_forward_sentence_end ("Hi. ", 3, 4, FALSE); /* FIXME result_offset should be 3 */
+  check_forward_sentence_end ("Hi. ", 3, 3, FALSE);
   check_forward_sentence_end ("Hi. ", 4, 4, FALSE);
+  check_forward_sentence_end ("Hi.", 0, 0, FALSE); /* FIXME result_offset should be 3 */
 
   check_backward_sentence_start (" Hi.", 4, 1, TRUE);
   check_backward_sentence_start (" Hi.", 3, 1, TRUE);